package com.zimmor.mq.rocket.base.producer;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

/**
 * @Author:zimmor
 * @Date: 2021/11/18 15:09
 * @Description 单项发送，只管发，不管是否发送结果
 * @version: 1.0.0
 */

public class OneWayProducer {
    public static void main(String[] args) throws Exception {
        //1.创建一个producer，设置groupId
        DefaultMQProducer producer = new DefaultMQProducer("group3");
        //2.设置namesrv地址，集群的话设置多个用分号隔开
        producer.setNamesrvAddr("192.168.204.136:9876;192.168.204.137:9876");
        //3.启动producer
        producer.start();
        for (int i = 0; i < 5; i++) {
            //4.创建消息，设置topic，tag，消息体
            Message message = new Message("base", "tag3", ("单向发送测试" + i).getBytes());
            //5.发送消息
            producer.sendOneway(message);

        }
        //6.关闭消息体
        producer.shutdown();
    }
}
